package model;

import base.BaseModel;
import base.BaseObserver;
import base.ResultCallBack;
import bean.CodeBean;
import bean.GuangGaoBean;
import bean.LoginBean;
import bean.Loginby_phonecodeBean;
import bean.ResultBean;
import jiyun.com.yiyanmeng.http.HttpManager;
import jiyun.com.yiyanmeng.http.MySerivce;
import utils.RxUtil;

/**
 * Created by Windows on 2019/11/5.
 */

public class LoginModel extends BaseModel {
    //请求账号密码登录接口
    public void requestLogin(final ResultCallBack<LoginBean> resultCallBack,String name,String pass) {
        MySerivce serivce = HttpManager.getInstance().getSerivce();
        serivce.login(name,pass).compose(RxUtil.<ResultBean<LoginBean>>changeThread())
                .compose(RxUtil.<LoginBean>changeResult())
                .subscribe(new BaseObserver<LoginBean>() {
                    @Override
                    public void onSuccess(LoginBean loginBean) {
                        resultCallBack.onSuccess(loginBean);
                    }

                    @Override
                    public void onFail(String error) {
                        resultCallBack.onFail(error);
                    }
                });
    }
    //请求验证码接口
    public void requestYanzhengma(final ResultCallBack<CodeBean> resultCallBack,String phone) {
        MySerivce serivce = HttpManager.getInstance().getSerivce();
        serivce.yanzhengma(phone, "6").compose(RxUtil.<ResultBean<CodeBean>>changeThread())
                .compose(RxUtil.<CodeBean>changeResult())
                .subscribe(new BaseObserver<CodeBean>() {
                    @Override
                    public void onSuccess(CodeBean codeBean) {
                        resultCallBack.onSuccess(codeBean);
                    }

                    @Override
                    public void onFail(String error) {
                        resultCallBack.onFail(error);
                    }
                });
    }
    //请求手机号验证码登录接口
    public void requestYanzhengma(final ResultCallBack<Loginby_phonecodeBean> resultCallBack, String type,String phone, String code) {
        MySerivce serivce = HttpManager.getInstance().getSerivce();
        serivce.loginby_phonecode(type,phone,code).compose(RxUtil.<ResultBean<Loginby_phonecodeBean>>changeThread())
                .compose(RxUtil.<Loginby_phonecodeBean>changeResult())
                .subscribe(new BaseObserver<Loginby_phonecodeBean>() {
                    @Override
                    public void onSuccess(Loginby_phonecodeBean loginby_phonecodeBean) {
                        resultCallBack.onSuccess(loginby_phonecodeBean);
                    }

                    @Override
                    public void onFail(String error) {
                        resultCallBack.onFail(error);
                    }
                });
    }
}
